package com.pomelo.kill.common;

import lombok.Data;

@Data
public class AjaxResult {
    private Integer code;
    private String msg;
    private Object result;

    private static final Integer SUCCESS_CODE = 1;
    private static final Integer FAIL_CODE = 0;

    private AjaxResult(Integer code, String msg, Object result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static AjaxResult success() {
        return success(null);
    }

    public static AjaxResult success(Object data) {
        return success("请求成功！", data);
    }

    public static AjaxResult success(String msg, Object result) {
        return new AjaxResult(SUCCESS_CODE, msg, result);
    }

    public static AjaxResult failure() {
        return failure("请求失败");
    }

    public static AjaxResult failure(String msg) {
        return new AjaxResult(FAIL_CODE, msg, null);
    }

}
